local app = require "app"
local gamelib = require "club.threecard.gamelib"
local base = require "ui.widgets.OnlineBonus"
local log = app.logging.get("online_bonus")

local M = gamelib.ui.element(base)

function M:on_update(quest)
    local reward = quest:get_rewards()[1]
    self.chip_txt.text = "+" .. app.i18n.number(reward.qty, "chip4")
end

function M:on_ready(quest)
    self.timer_txt.text = app.i18n.text("online_bonus:ready")
    self.animator:SetBool("AdsReady", false)
    self.animator:SetBool("Ready", true)
end

function M:on_boostable(quest)
    self.timer_txt.text = quest:get_remain_time():ToString("mm\\:ss")
    self.animator:SetBool("AdsReady", true)
    self.animator:SetBool("Ready", false)
end

function M:on_countdown(quest)
    self.timer_txt.text = quest:get_remain_time():ToString("mm\\:ss")
    self.animator:SetBool("AdsReady", false)
    self.animator:SetBool("Ready", false)
end

function M:get_chip_transform()
    return self.loaded and self.chip_root.transform or nil
end

function M:on_injected(bind)
    bind("button.click", self.button, self.on_click)
    bind("gameobject.enable", self.gameobject, self.update)
    self.animator.keepAnimatorControllerStateOnDisable = true
end

return M